<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset=utf8>
</head>
<body>
  
    <script>
      var str = new String('恢弘的城址、精美的玉器、丰沛的粮食储备');
      var str = String(true);
      var str = 'I am jingjing, I love you,do you zao?上海!';

      console.log(str);
      console.log(typeof str);
      console.log(str.constructor);

      document.write('STR长度:' + str.length +'<br>');
      document.write(str+'<br>');

      document.write('加粗:'+str.bold()+'<br>');
      document.write('锚点:'+str.anchor('p1')+'<br>');

      document.write('charAt:'+str.charAt(2) + '<br>');
      document.write('类数组语法' + str[2] + '<br>');


      document.write('<hr>');

      document.write('indexOf:'+str.indexOf('you')+'<br>');
      document.write('indexOf:'+str.indexOf('kkk')+'<br>');
      document.write('lastIndexOf:'+str.lastIndexOf("you")+'<br>');
      document.write('lastIndexOf:'+str.lastIndexOf('kikk')+'<br>');
      document.write('indexOf:'+str.indexOf('呵')+'<br>');

      document.write('<hr>');
      // substr(start,length)
      // 截取字符串,无指定长度则截取到尾部位置
      document.write('substr:'+str.substr(22)+'<br>');
      document.write('substr:'+str.substr(3,6)+'<br>');
      document.write('substr:'+str.substr(-3,2)+'<br>');
      // substring(start,end)
      // 截取字串,从start开始到end结束,不含end.参数不得为负数
      document.write('substring:'+str.substring(22)+'<br>');
      document.write('substring:'+str.substring(3,6)+'<br>');
      document.write('substring:'+str.substring(-3,-1)+'<br>');
      // slice(start,end)
      // 截取字串,从start开始到end结束,不含end,参数可以为负数
      document.write('slice:'+str.slice(22)+'<br>');
      document.write('slice:'+str.slice(3,6)+'<br>');
      document.write('slice:'+str.slice(-3,-1)+'<br>');

      document.write('toLowerCase:'+str.toLowerCase()+'<br>');
      document.write('toUpperCase:'+str.toUpperCase()+'<br>');

      document.write('<hr>');

      document.write('replace:'+str.replace('you','你')+'<br>');
      document.write('replace:'+str.replace(/you/,'你')+'<br>');
      document.write('replace:'+str.replace(/\w/,'你')+'<br>');
      document.write('replace:'+str.replace(/\w/g,'你')+'<br>');
      document.write('replace:'+str.replace(/\d/g,'你')+'<br>');

      //match()  匹配第一个匹配到的结果,不匹配返回null
      document.write('match:'+str.match('a')+'<br>');
      document.write('match:'+str.match('k')+'<br>');
      document.write('match:'+str.match(/\w{8}/)+'<br>');
      document.write('match:'+str.match(/\w{88}/)+'<br>');
      

      //split把字符串分割为数组
      console.log(str.split());
      console.log(str.split(','));
      console.log(str.split(''));
      console.log(str.split(/[, ?]/));
      

    </script>


    
</body>
</html>